package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐的数量
     * @param id
     * @return
     */
    @Select("select count(id) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long id);

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 新增
     * @param setmeal
     */
    @AutoFill(OperationType.INSERT)
    @Options(keyProperty = "id", useGeneratedKeys = true)
    @Insert("insert into setmeal (category_id, name, price, status, description, image, create_time, update_time, create_user, update_user)VALUE " +
            "(#{categoryId} , #{name} , #{price} , #{status} ,#{description} , #{image} , #{createTime} , #{updateTime} , #{createUser} , #{updateUser})")
    void insert(Setmeal setmeal);

    /**
     * 修改
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 根据ID查询套餐
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal getById(Long id);

    /**
     * 根据套餐ID获取状态
     * @param id
     * @return
     */
    @Select("select status from setmeal where id = #{id}")
    Object getStatus(Long id);

    /**
     * 删除
     * @param id
     */
    @Delete("delete from setmeal where id = #{id}")
    void delete(Long id);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name , sd.copies , d.image , d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);

//    /**
//     * 根据分类ID查询套餐-用户端
//     * @param setmeal
//     * @return
//     */
//    @Select("select * from setmeal where status = 1 and category_id = #{categoryId}")
//    List<Setmeal> getSetmeal(Setmeal setmeal);
}
